package com.w2cx.selenium.business;

import com.w2cx.selenium.base.DriverBase;
import com.w2cx.selenium.operate.MarkCategoryManageOperate;
import org.openqa.selenium.WebElement;

import java.util.List;

public class MarkCategoryManageProcess {
    DriverBase driver;
    MarkCategoryManageOperate mcmh;
    public MarkCategoryManageProcess(DriverBase driver){
        this.driver = driver;
        mcmh = new MarkCategoryManageOperate(driver);
    }

    //添加标签分类
    public void markCategoryAdd(String categoryName){
             //点击“基础数据管理”菜单
            mcmh.clickBaseDataManageMenu();

            //点击“标签分类管理”菜单
            mcmh.clickMarkCategoryManageMenu();

            //点击添加
            mcmh.clickAddBtn();

            //刷新页面
             driver.refresh();
             //输入“分类名称”
            mcmh.inputCategoryName(categoryName);

            //点击“确定”按钮
            mcmh.clickConfirmBtn();

    }


    //判断是否新增成功
    public boolean addMarkCategorySuccess(String alreadyAddCategoryName){
        //刷新列表
        driver.refresh();
        List<WebElement> list = mcmh.getMarkCategoryList();
        for (WebElement element:list){
            if(element.getText().contains(alreadyAddCategoryName)){
                return true;
            }
        }
        return false;
    }

    //删除标签分类
    public void delMarkCategory(String alreadyAddCategoryName){
        mcmh.clickDelBtn(alreadyAddCategoryName);
    }

    //判断删除是否成功
    public boolean delMarkCategorySuccess(String alreadyAddCategoryName){
        //刷新列表
        driver.refresh();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        List<WebElement> list = mcmh.getMarkCategoryList();
        for (WebElement element:list){
            if (element.getText().contains(alreadyAddCategoryName)) {

                return false;
            }
        }
        return true;
    }


}
